package com.ruoyi.bizsys.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bizsys.domain.AwardActConfigRelation;
import com.ruoyi.bizsys.service.IAwardActConfigRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动-奖励配置关联Controller
 *
 * @author african-loan
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/award/actConfigRelation")
public class AwardActConfigRelationController extends BaseController {
    @Autowired
    private IAwardActConfigRelationService awardActConfigRelationService;

    /**
     * 查询活动-奖励配置关联列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardActConfigRelation awardActConfigRelation) {
        startPage();
        List<AwardActConfigRelation> list = awardActConfigRelationService.selectAwardActConfigRelationList(awardActConfigRelation);
        return getDataTable(list);
    }

    /**
     * 导出活动-奖励配置关联列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:export')")
    @Log(title = "活动-奖励配置关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardActConfigRelation awardActConfigRelation) {
        List<AwardActConfigRelation> list = awardActConfigRelationService.selectAwardActConfigRelationList(awardActConfigRelation);
        ExcelUtil<AwardActConfigRelation> util = new ExcelUtil<AwardActConfigRelation>(AwardActConfigRelation.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 获取活动-奖励配置关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardActConfigRelationService.selectAwardActConfigRelationById(id));
    }

    /**
     * 新增活动-奖励配置关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:add')")
    @Log(title = "活动-奖励配置关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardActConfigRelation awardActConfigRelation) {
        return toAjax(awardActConfigRelationService.insertAwardActConfigRelation(awardActConfigRelation));
    }

    /**
     * 修改活动-奖励配置关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:edit')")
    @Log(title = "活动-奖励配置关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardActConfigRelation awardActConfigRelation) {
        return toAjax(awardActConfigRelationService.updateAwardActConfigRelation(awardActConfigRelation));
    }

    /**
     * 删除活动-奖励配置关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:remove')")
    @Log(title = "活动-奖励配置关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardActConfigRelationService.deleteAwardActConfigRelationByIds(ids));
    }

}
